//
//  LocationHelper.m
//  jandaobao
//
//  Created by 杨志刚 on 15/5/27.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "LocationHelper.h"
#import "AppDelegate.h"



@implementation LocationHelper


+(Boolean) isLoginOrNot{
    NSString* customerString =[NSString stringWithFormat:@"%@",[self getCustomerId]];
    if(customerString ==nil || [customerString isEqualToString:@"0"]) return false;
    
    int customerId = [customerString intValue];
    if(customerId<=0) return false;
    
    return true;
}

+(Boolean) checkLogin{
    Boolean loginOrNot = [self isLoginOrNot];
    if(loginOrNot) return true;

    return false;
}


+(NSString *)getTodayShareUrl:(NSString *)campaignId{
    return [NSString stringWithFormat:@"http://jiandaobao.nuodaowuxian.com/App/Campaign/Detail?CampaignId=%@",campaignId];
}

/*************
 *获取用户的所在的belongAgent;
 ****************/
+(NSString *) getBelongAgentId{
    NSString *belongAgentId = [[NSUserDefaults standardUserDefaults]objectForKey:@"beLongAgentId"] ;
    if(belongAgentId==nil)
        belongAgentId = [[NSUserDefaults standardUserDefaults]objectForKey:@"BeLongAgentId"] ;
    
    if(belongAgentId==nil) return @"0";
    
    return belongAgentId;
}

/*************
 *获取用户的id,
 ****************/
+(NSString *) getCustomerId{
   NSString * customerId =  [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    if(customerId==nil) return @"0";
    return customerId;
}


+(void)setVendorImageUrl:(UIImageView *)image:(NSString *)imgPath {
    
        [image setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"默认头像"]];
}


+(NSURL *)getImageUrl:(NSString *)imagePath{
    
    return [NSURL URLWithString:[NSString stringWithFormat:@"%@",imagePath]];
}


+(NSString *) getFirstInfo{
    NSString * firstInfo = [[NSUserDefaults standardUserDefaults]objectForKey:@"FIRSTINSERTINFO"];
    if(firstInfo==nil) return @"jiandaobao";
    
    return firstInfo;
}

+(NSString *) getCurrentLatitude{
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"latitude"];
}

+(NSString *) getCurrentLongitude{
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"longitude"];
}

//+(NSString *) getDistinceByLatLog:(double)lat :(double)log{
//    BMKMapPoint point1 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(lat,log));
//    
//    double currentLatitude =  [[[NSUserDefaults standardUserDefaults]objectForKey:@"latitude"] doubleValue];
//    double currentLongitude =  [[[NSUserDefaults standardUserDefaults]objectForKey:@"longitude"] doubleValue];
//    
//    BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(currentLatitude,currentLongitude));
//    CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);
//  
//    if(distance<1000)
//        return [NSString stringWithFormat:@"%.0f米",distance];
//    
//    if(distance>=1000) return [NSString stringWithFormat:@"%.1f千米",distance/1000];
//    
//     if(distance<=50)  return [NSString stringWithFormat:@"小于50米"];
//    
//    return @"大于10千米";
//}

+(id )getNSDictionaryByBaseResult:(id)baseResult{
    if(baseResult == nil) return nil;
    return (NSDictionary *)[baseResult objectForKey:@"Result"];
}

//+(ResultStatus)getResultStatusByBaseResult:(id)baseResult{
//    if(baseResult==nil) return Empty;
//    int status = [[baseResult objectForKey:@"IsSuccess"] intValue];
//    if(status==1) return Success;
//    if(status==2) return Error;
//    return Empty;
//}

+(NSString *)getMessageByBaseResult:(id)baseResult{
    if(baseResult==nil) return @"";
    
    return [baseResult objectForKey:@"Message"];
}

+(id)getResultByBaseResult:(id)baseResult{
      return [baseResult objectForKey:@"Result"];
}
@end
